package com.hmdp.dto;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class Result {
    private Integer code;
    private Boolean success;
    private String message;
    private Object data;
    private Long total;

    //    @AllArgsConstructor：该注解会使 Lombok 自动生成一个包含所有字段的全参构造函数
//public Result(Boolean success, String message, Object data, Long total) {
//    this.success = success;
//    this.message = message;
//    this.data = data;
//    this.total = total;
//}
    public static Result ok() {
        return new Result(200, true, null, null, null);
    }

    public static Result ok(Object data) {
        return new Result(200, true, null, data, null);
    }

    public static Result ok(List<?> data, Long total) {
        return new Result(200, true, null, data, total);
    }

    public static Result fail(String message) {
//        TODO:请求错误时，状态码还有待修改
        return new Result(401, false, message, null, null);
    }
}
